package com.dhl.cloud.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 上传文件的配置
 */
@Configuration
public class UploadFileConfig implements WebMvcConfigurer {

	@Value("${fileUpload.rootSavePath}")
	private String rootSavePath;
//	@Value("${resource.userPath}")
//	private String userRootSavePath;
//	@Value("${resource.sysPath}")
//	private String sysRootSavePath;
	
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
    	String os = System.getProperty("os.name");
    	if (os.toLowerCase().startsWith("win"))
    	{
    		registry.addResourceHandler("/Path/**").addResourceLocations("file:/"+rootSavePath);
//			registry.addResourceHandler("/SYS/**").addResourceLocations("file:/"+sysRootSavePath);
//			registry.addResourceHandler("/USER/**").addResourceLocations("file:/"+userRootSavePath);
		}
    	else
    	{
    		registry.addResourceHandler("/Path/**").addResourceLocations("file:"+rootSavePath);
//			registry.addResourceHandler("/SYS/**").addResourceLocations("file:"+sysRootSavePath);
//			registry.addResourceHandler("/USER/**").addResourceLocations("file:"+userRootSavePath);
    	}
    }
}